package fields;

import gui.G;
import model.Player;
import view.Boundary;

public class Tax  extends Field{
	private int taxAmount, taxPercentage;
	private String displayText;
	
	public Tax(int number, String name, int taxAmount, String displayText) {
		this(number, name, taxAmount, -1, displayText);
	}
	public Tax(int number, String name, int taxAmount, int taxPercentage, String displayText){
		super(number, name);
		this.taxAmount = taxAmount;
		this.taxPercentage = taxPercentage;
		this.displayText = displayText;
		Boundary.setTitleText(getNumber(), getName());
		Boundary.setSubText(getNumber(), getDisplayText());
	}

	@Override
	public void landOnField(Player player) {
		if(this.taxPercentage == -1){
			Boundary.showMessage("You landed on " + getNumber() + " " + getName().replace("-<br>", "") + ","
				+ "\nand have to pay " + this.taxAmount + ".");
			player.withdraw(this.taxAmount); 
		}else{
			String[] options = {""+this.taxPercentage + "%", ""+this.taxAmount};
			String selection = G.getUserButtonPressed("You landed on " + getNumber() + " " + getName().replace("-<br>", "") + ","
				+ "\nand have to pay tax.\nSelect payment option?", options);
			if(selection == options[0]){
				int playerWorth = player.calculatePlayerWorth();
				player.withdraw(playerWorth * this.taxPercentage / 100);
			}else{
				player.withdraw(this.taxAmount);
			}
		}
	}

	public String getDisplayText() {
		return this.displayText;
	}

	@Override
	public String toString() {
		return "Tax\t["+ super.toString() + " " + getName() + " " + getDisplayText() + "]";
	}
}